// Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.

// 常量定义
package common

import (
	"errors"
	"github.com/google/uuid"
)

const (
	PolicyTypeTargetBased = "TARGET_BASED"

	DiskTypeSYS  = "SYS"
	DiskTypeDATA = "DATA"

	MinSizeOfDiskSYS  int32 = 1
	MaxSizeOfDiskSYS  int32 = 1024
	MinSizeOfDiskDATA int32 = 10
	MaxSizeOfDiskDATA int32 = 32768

	DefaultCoolDownTime      int64 = 5 // 单位：分钟
	MaxLengthOfParamName           = 128
	MaxNumberOfParamLimit          = 100
	MaxNumberOfParamOffset         = 2147483647
	DefaultVMTimeOutDuration       = 2 // 单位：分钟
)

var (
	LocalWorkNodeId = uuid.NewString()

	ErrScalingGroupNotStable       = errors.New("the scaling group state is not stable")
	ErrDeleteTaskAlreadyExists     = errors.New("delete group task already exists in db")
	ErrScalingGroupCannotBeDeleted = errors.New("the scaling group cannot be deleted at present")
	ErrScalingDecisionExpired      = errors.New("scaling decision expired")
	ErrScalingGroupNotExist        = errors.New("scaling group do not exist")
	ErrScalingGroupInCoolDown      = errors.New("scaling group in cool down time")
	ErrAsInstanceIdInvalid         = errors.New("the as scaling instance id invalid")
	ErrNoNeedToDo                  = errors.New("no need to do something")
	ErrPodNotFound                 = errors.New("pod not found")
)

const (
	ScalingActivatySuccess = "SUCCESS"
	ScalingActivatyFail    = "FAIL"
	ScalingActivatyDoing   = "DOING"
)

const (
	InstanceStateActive     = "ACTIVE"
	InstanceStateActivating = "ACTIVATING"
	InstanceStateDeleted    = "DELETED"
	InstanceStateDeleting   = "DELETING"
	InstanceStateFailed     = "FAILED"
)

const (
	ParamStartNumber   = "start_number"
	DefaultStartNumber = 0
	ParamLimit         = "limit"
	ParamOffset        = "offset"
	DefaultLimit       = 100
	DefaultOffset      = 0
	ParamCreatedAt     = "created_at"
	ParamState         = "state"
	ParamHealthState   = "health_state"
	ParamJobType       = "job_type"

	TimeLayout                 = "2006-01-02T15:04:05Z"
	SleepSecond                = 10
	AsyncMaxRetryTimes         = 10
	AsyncScaleOutMaxRetryTimes = 3
)

const (
	LifeCycleStateInservice       = "INSERVICE"
	LifeCycleStatePending         = "PENDING"
	LifeCycleStateRemoving        = "REMOVING"
	LifeCycleStatePendingWait     = "PENDING_WAIT"
	LifeCycleStateRemovingWait    = "REMOVING_WAIT"
	LifeCycleStateStandby         = "STANDBY"
	LifeCycleStateEnteringStandby = "ENTERING_STANDBY"

	HealthStateInitializing = "INITIALIZING"
	HealthStateNormal       = "NORMAL"
	HealthStateError        = "ERROR"
)

const (
	TableNameScalingGroup   = "scaling_group"
	FleetId                 = "fleet_id"
	TableNameVmScalingGroup = "vm_scaling_group"
)

const (
	DistributedLockKey          = "aass_health_check_lock"
	LockExpiredSecond           = 60
	TryOrLeaseInterval          = 30
	InstanceCountToSleep        = 50
	InstanceCountToSleepSeconds = 1
	CleanUpDataDisLockKey       = "aass_clean_up_lock"
)

// event
const (
	EventResourceTraceService = "aass"
	EventTraceStateNormal     = "NORMAL"
	EventTraceStateWarning    = "WARNING"
	EventTraceStateIncident   = "INCIDENT"
	EventTypeData             = "data"
	EventTypeManager          = "manager"
	EventResourceTypeInstance = "instance"
	DefaultListEventLimit     = 5000
)

// cci
const (
	CCICreatedCode     = 201
	CCIQueryCode       = 200
	CCINotFoundCode    = 404
	Release            = "RELEASE"
	XStage             = "x-stage"
	NamespaceURL       = "/api/v1/namespaces"
	CreatePodURL       = "/api/v1/namespaces/%s/pods"
	CreateNetworkURL   = "/apis/networking.cci.io/v1beta1/namespaces/%s/networks"
	QueryPodURL        = "/api/v1/namespaces/%s/pods/%s"
	DeleteNamespaceURL = "/api/v1/namespaces/%s"
	PodCountToSleep    = 200
	SleepMinToPod      = 1
	GateWayAddressKey  = "GATEWAYADDRESS"
)

const (
	EnvInstanceType = "INSTANCE_TYPE"
	InstanceTypeVM  = "VM"
	InstanceTypePod = "POD"
)

const (
	PublicIP  = "publicIP"
	PrivateIP = "privateIP"
)
